import {
    useAdminStore
} from '../stores/index.js'
const admin = JSON.parse(localStorage.getItem('admin'))
const hasPermission = (value,el = false) =>{
    // console.log(value,el);
    // if (!Array.isArray(value)) {
    //     throw new Error(`需要配置权限，例如 v-permission="['/admin/index,GET']"`)
    // }
// console.log(admin);
    const hasAuth = admin.includes(value) 
    // console.log(hasAuth);
    if (el && !hasAuth) {
        el.parentNode && el.parentNode.removeChild(el)
    }
    return hasAuth
}

export default {
    install(app) {
        // console.log(app);
        app.directive("permission", {
            mounted(el, binding) {
                // console.log(el, binding);
                hasPermission(binding.value, el)
            }
        })
    }
}